package com.team.ssm_item_lj.service.impl;

import com.team.ssm_item_lj.entity.WasteTypes;
import com.team.ssm_item_lj.dao.WasteTypesDao;
import com.team.ssm_item_lj.service.WasteTypesService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

/**
 * 垃圾类型表(WasteTypes)表服务实现类
 *
 * @author zhuxhenxin
 * @since 2024-12-05 10:44:30
 */
@Service("wasteTypesService")
public class WasteTypesServiceImpl implements WasteTypesService {
    @Resource
    private WasteTypesDao wasteTypesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public WasteTypes queryById(Integer id) {
        return this.wasteTypesDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param wasteTypes 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<WasteTypes> queryByPage(WasteTypes wasteTypes, PageRequest pageRequest) {
        long total = this.wasteTypesDao.count(wasteTypes);
        return new PageImpl<>(this.wasteTypesDao.queryAllByLimit(wasteTypes, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param wasteTypes 实例对象
     * @return 实例对象
     */
    @Override
    public WasteTypes insert(WasteTypes wasteTypes) {
        this.wasteTypesDao.insert(wasteTypes);
        return wasteTypes;
    }

    /**
     * 修改数据
     *
     * @param wasteTypes 实例对象
     * @return 实例对象
     */
    @Override
    public WasteTypes update(WasteTypes wasteTypes) {
        this.wasteTypesDao.update(wasteTypes);
        return this.queryById(wasteTypes.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.wasteTypesDao.deleteById(id) > 0;
    }
}
